PATHMac OS 8 and 9 Developer Documentation > Interapplication Communication > AppleScript for Scripters >

AppleScript Language Guide

   

Scope of Variables

The scope of a variable determines where else in a script you may refer to the same variable. The scope depends on where you declare a variable and whether you declare it as global or local.

After you define a global variable in a script, you can make subsequent references to the same variable either at the top level of the script or in any of the script's subroutines. After you define a local variable, you can make subsequent references to the same variable only at the same level of the script at which you defined the variable.

AppleScript assumes that all variables defined at the top level of a script or within its subroutines are local unless you explicitly declare them as global. For more detailed information and examples of the use of variables in subroutines, see Recursive Subroutines.

You can also declare variables within script objects. The scope of variables in a script object is limited to that script object. For more information, see Scope of Script Variables and Properties.


© 1999 Apple Computer, Inc. – (Last Updated 21 May 99)